/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.action;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.pay.core.model.common.SystemConstants;
import org.grayrabbit.web.struts2.GenericAction;
import org.grayrabbit.web.struts2.Struts2Utils;

/**
 * 登录相关操作
 * 
 * @author wy
 * @version $Id: LoginAction.java, v 0.1 2012-6-11 下午4:37:14 wy Exp $
 */
@Results({
    @Result(name = GenericAction.RELOAD, location = "main", type = "redirectAction"),
    @Result(name = LoginAction.LOGIN, location = "login", type = "redirectAction")
    })
public class LoginAction extends GenericAction {
   
    public static final String LOGIN = "login";
    
    /**serialVersionUID  */
    private static final long serialVersionUID = -5806656403059579333L;
    
    private String username;
    private String password;

    /**
     * 用户登录
     */
    @Action("login")
    public String login(){
        if(StringUtils.isBlank(username)||StringUtils.isBlank(password)){
            return SUCCESS;
        }
        else if("admin".equals(username)&&"admin".equals(password)){
            Struts2Utils.getSession().setAttribute(SystemConstants.SESSION_ADMIN, username);
            return RELOAD;
        }
        addActionError("用户名或者密码输入错误");
        return SUCCESS;
        
    }
    
    @Action("logout")
    public String logout(){
        Struts2Utils.getSession().invalidate();
        return LOGIN;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}
